<template>
	<view>
		<view class="login">
			<view class="loginLove">登录恋爱吧</view>
			<view class="change">
				<view class="">成为知心爱人</view>
				<view class="">共建心灵港湾</view>
			</view>
		</view>
		<view class="number">
			<u--input class="inp" border="bottom" name="phone" bindinput="phone" placeholder="请输入手机号" clearable
				prefixIcon="+86 | " prefixIconStyle="font-size: 14px;color: #000">
			</u--input>
			<!-- #ifndef APP-NVUE -->
			<u-input placeholder="输入验证码" border="bottom" style="border-bottom: 1px solid #ccc;" @change="num()"
				v-model="input">
				<!-- #endif -->
				<!-- #ifdef APP-NVUE -->
				<u--input placeholder="后置插槽">
					<!-- #endif -->
					<template slot="suffix">
						<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
						<u-button @tap="getCode" :text="tips" type="primary" size="mini"></u-button>
					</template>
					<!-- #ifndef APP-NVUE -->
			</u-input>
			<!-- #endif -->
			<!-- #ifdef APP-NVUE -->
			</u--input>
			<!-- #endif -->
			<u-button type="primary" text="确定" style="margin-top: 30px;" @click="btnLogin"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		getLoginCode
	} from "../../api/index.js"
	export default {
		data() {
			return {
				tips: '',
				input: '',
				code:''
			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					setTimeout(() => {
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
						getLoginCode({
							mobile: 13310885348
						}).then(res => {
							console.log(res);
							this.code = res.data.code
						})
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			num() {
				console.log(this.input);
			},
			// 验证成功跳转页面
			btnLogin() {
				if (this.input === this.code) {
					uni.navigateTo({
						url: '/pages/loginT/loginT'
					})
				}
			console.log(this.code);
			},
		}
	}
</script>

<style lang="scss">
	.login {
		background-color: #0084ff;
		height: 100px;
		color: #fff;
		margin-bottom: 30px;

		.loginLove {
			text-align: center;
			padding-top: 20px;
		}

		.change {
			padding-top: 20px;
			display: flex;
			justify-content: space-around;
		}
	}

	.number {
		padding: 0 10px;

		.inp {
			border-bottom: 1px solid #ccc;
			margin-bottom: 20px;
		}

	}
</style>
